<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta content="IE=edge" http-equiv="X-UA-Compatible"/>
    <title>iframe 示例</title>
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<script>
    let _iframe

    function getIframe() {
        _iframe ||= document.getElementById('sr-iframe')
        return _iframe
    }

    function sendMessage(event, data) {
        console.log('sendMessage', event, data)
        const iframe = getIframe()
        setTimeout(() => {
            iframe.contentWindow.postMessage(
                {
                    source: 'sr-parent',
                    event,
                    data,
                },
                '*',
            )
        }, 0)
    }
</script>

<iframe
        id="sr-iframe"
        onload="sendMessage('init', {aaa: 1})"
        src="http://localhost:7314/model"
        style="width: 100%; height: 100%; border: none"
/>
</body>
</html>
